package com.tx.wsclient;


import com.fbg.model.WsClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author dengguoxing
 * @date 2019/11/1
 * description 管理ws链接客户端
 **/
public class WsClientManager {

    private static final Logger logger = LoggerFactory.getLogger(WsClientManager.class);

    /**
     * id - wsClient
     */
    public static Map<String,WsClient> wsClientCache = new ConcurrentHashMap<>(256);


    /**
     * 统一添加WsClient
     * @param id
     * @param wsClient
     */

    public static  void addWsClient(String id,WsClient wsClient){
        wsClientCache.put(id,wsClient);

    }

    /**
     * 统一删除WsClient
     * @param id
     * @param wsClient
     */

    public static  void delWsClient(String id){
        wsClientCache.remove(id);
        logger.info("wsClientCache remove wsClient, id: {}", id);
    }

    /**
     * 统一获取WsClient
     * @param id
       *
     */

    public static  WsClient getWsClient(String id){
       return wsClientCache.get(id);


    }







}
